package com.oocl.homework.format.moel;

import java.lang.reflect.Field;
import java.util.Map;

import com.oocl.homework.exception.VerifyException;
import com.oocl.homework.verify.Verifyable;

public class CustomerFactory {
	
	public static Customer getInstanceWithVerify(Map<String, String> map,Verifyable verifyable) throws VerifyException{
		 Field[] fields = Customer.class.getDeclaredFields();
		 Customer customer = new Customer();
	        for(Field field :fields){
	        	try {
	        		field.setAccessible(true);
					field.set(customer, map.get(field.getName()));
	        	} catch (IllegalArgumentException e) {
					throw new VerifyException(field.getName()+" Assignment failure,IllegalArgument", e);
				} catch (IllegalAccessException e) {
					throw new VerifyException(field.getName()+" Assignment failure,IllegalAccess", e);
				}
	        }
	        Customer result = (Customer) verifyable.verify(customer);
		
		return result;
		
	}

}
